<!--title-->
<div class="mnav1">
	<div class="m_nav">
		<div class="nav_left">
			<em class="home_icon"><?=$this->sys_name?></em><span>&nbsp;&gt;&nbsp;</span><font><?=$this->title?></font>
		</div>
	</div>
</div>

<div class="content-table2">
<div class="content-table-title"><?=$this->title?></div>
<div class="form-edit-task">

<form action="/clients/add-client-submit" method="post" name="form1" onsubmit="submitform(this);return false;">
<table border="0" width="100%">
	<tr>
		<td align="right" width="30%">客户全称：</td>
		<td align="left">&nbsp;<input type="text" placeholder="客户全称" name="client_name" id="client_name" style="width: 300px"><font color="red"> *</font></td>
	</tr>
	<tr>
		<td align="right">省份：</td>
		<td align="left"><select name="provinceId" id="provinceId" onchange="GetCities(this.options[this.options.selectedIndex].value);">
					<option value="">不限</option>
					<?php if(!empty($this->provinces)):?>
					<?php foreach($this->provinces as $provinceId => $provinceName):?>
					<option value="<?=$provinceId?>"><?=$provinceName?></option>
					<?php endforeach;?>
					<?php endif;?>
				</select><font color="red"> *</font>
		</td>
	</tr>
	<tr>
		<td align="right">城市：</td>
		<td align="left"><select name="cityId" id="cityId" onchange="GetCounties(this.options[this.options.selectedIndex].value);"></select><font color="red"><font color="red"> *</font></td>
	</tr>
	<tr>
		<td align="right">区/县：</td>
		<td align="left"><select name="countyId" id="countyId"></select><font color="red"><font color="red"> *</font></td>
	</tr>
	<tr>
		<td align="right">联系地址：</td>
		<td align="left">&nbsp;<input type="text" placeholder="地址" name="address" id="address" style="width: 400px"></td>
	</tr>
	<tr>
		<td align="right">邮编：</td>
		<td align="left">&nbsp;<input type="text" placeholder="邮编" name="zipcode" id="zipcode"></td>
	</tr>
	<tr>
		<td align="right">电话：</td>
		<td align="left">&nbsp;<input type="text" placeholder="电话" name="tel" id="tel"></td>
	</tr>
	<tr>
		<td align="right">手机：</td>
		<td align="left">&nbsp;<input type="text" placeholder="手机" name="cellphone" id="cellphone"></td>
	</tr>
	<tr>
		<td align="right">传真：</td>
		<td align="left">&nbsp;<input type="text" placeholder="传真" name="fax" id="fax"></td>
	</tr>
	<tr>
		<td align="right">类型：</td>
		<td align="left"><select name="client_type_id" id="client_type_id">
				<option value=""></option>
				<?php foreach($this->client_types as $client_type_id => $type_name):?>
				<option value="<?=$client_type_id?>"><?=$type_name?></option>
				<?php endforeach;?>
		</select><font color="red"><font color="red"> *</font></td>
	</tr>
	<tr>
		<td align="right">厂商：</td>
		<td align="left"><select name="factory_id" id="factory_id">
				<option value=""></option>
				<?php foreach($this->factories as $factory_id => $factory_name):?>
				<option value="<?=$factory_id?>"><?=$factory_name?></option>
				<?php endforeach;?>
		</select></td>
	</tr>
	<tr>
		<td align="right">签约公司：</td>
		<td align="left">
			<select name="signer_id" id="signer_id">
				<option value="">【申请为签约公司】</option>
				<?php if($this->signers):?>
				<?php foreach($this->signers as $signer_id => $signer_name):?>
				<option value="<?=$signer_id?>"><?=$signer_name?></option>
				<?php endforeach;?>
				<?php endif;?>
			</select>
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center"><input type="button" class="buttonlong" value="提交审核" onclick="submitform();return false;" /></td>
	</tr>
</table>
<br /><br />
</form>
</div>
<br/><br/>
</div>

<script>
<?php if($this->msg):?>
alert("<?=$this->msg?>, 信息提交失败, 请修改后再次提交。");
<?php endif;?>

function GetCities(provinceId)
{
	$.ajax({
			type: "post",
			url : "/ajax/get-cities",
			dataType:'json',
            async:false,
			data: {
					'provinceId':provinceId
				  },
				success: function(json){
					if(json.result == 1 && typeof(json.data) != "undefined") {
                        var arr = json.data;
						var txt = "<option value=''>不限</option>";
						
                        for(i=0; i < arr.length; i++){
							txt += "<option value='" + arr[i]['cityId'] + "'>" + arr[i]['cityName'] + "</option>";
                        }
						
						document.getElementById("cityId").innerHTML = txt;
                    }
			}
		});
}

function GetCounties(cityId)
{
	$.ajax({
			type: "post",
			url : "/ajax/get-counties",
			dataType:'json',
            async:false,
			data: {
					'cityId':cityId
				  },
				success: function(json){
					if(json.result == 1 && typeof(json.data) != "undefined") {
                        var arr = json.data;
						var txt = "<option value=''>不限</option>";
						
                        for(i=0; i < arr.length; i++){
							txt += "<option value='" + arr[i]['countyId'] + "'>" + arr[i]['countyName'] + "</option>";
                        }
						
						document.getElementById("countyId").innerHTML = txt;
                    }
			}
		});
}

function submitform() 
{
	
	if( document.form1.client_name.value.length == 0 )
	{
		alert("客户全称不能为空。");
		return false;
	}else if( document.form1.provinceId.value.length == 0 )
	{
		alert("省份不能为空。");
		return false;
	}else if( document.form1.cityId.value.length == 0 )
	{
		alert("城市不能为空。");
		return false;
	}else if( document.form1.client_type_id.value.length == 0 )
	{
		alert("类型不能为空。");
		return false;
	}
	
	form1.submit();
}
</script>
